﻿/*
 * @Author: ws.s 
 * @Date: 2021-05-31 10:17:43 
 * @Last Modified by: ws.s
 * @Last Modified time: 2021-07-13 21:10:40
 */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace WssUtils
{
    public static class StringExtentions
    {

        /// <summary>
        /// 首字母大写，其他小写
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ToFirstCharUpper(this string s)
        {
            return s.Substring(0, 1).ToUpper() + s.Substring(1).ToLower();
        }

        private static List<string[]> _cacheList = new List<string[]>();

        [System.Obsolete("请使用 Split2DArray 代替 SplitTwice，注意参数顺序")]
        public static string[][] SplitTwice(this string s, char split1, char split2)
        {
            return Split2DArray(s, split2, split1);
        }

        /// <summary>
        /// 二次分隔
        /// </summary>
        /// <param name="s"></param>
        /// <param name="split1"></param>
        /// <param name="split2"></param>
        /// <returns></returns>
        public static string[][] Split2DArray(this string s, char split1 = ',', char split2 = ';')
        {
            var subStrArr = s.Split(split2);
            _cacheList.Clear();

            for (int i = 0; i < subStrArr.Length; i++)
            {
                if (string.IsNullOrEmpty(s)) continue;
                string sub = subStrArr[i];
                var valueParams = sub.Split(split1);
                _cacheList.Add(valueParams);
            }

            return _cacheList.ToArray();
        }

    }
}

